package com.gewu.pm.ui.adapter.order;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.gewu.pm.R;
import com.gewu.pm.app.AppAdapter;
import com.gewu.pm.bean.PaymentReceiptBean;

/**
 * 收款单适配器
 */
public final class PaymentReceiptAdapter extends AppAdapter<PaymentReceiptBean> {

    public PaymentReceiptAdapter(Context context) {
        super(context);
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new ReceiptHolder();
    }

    private final class ReceiptHolder extends AppAdapter<?>.ViewHolder {

        private final TextView tvTerminalName;
        private final TextView tvSubmitter;
        private final TextView tvSubmitTime;
        private final TextView tvReceiptNo;
        private final TextView tvTag;
        private final TextView tvPaymentMethod;
        private final TextView tvAmount;

        private ReceiptHolder() {
            super(R.layout.payment_receipt_item);
            tvTerminalName = findViewById(R.id.tv_terminal_name);
            tvSubmitter = findViewById(R.id.tv_submitter);
            tvSubmitTime = findViewById(R.id.tv_submit_time);
            tvReceiptNo = findViewById(R.id.tv_receipt_no);
            tvTag = findViewById(R.id.tv_tag);
            tvPaymentMethod = findViewById(R.id.tv_payment_method);
            tvAmount = findViewById(R.id.tv_amount);
        }

        @Override
        public void onBindView(int position) {
            PaymentReceiptBean item = getItem(position);
            
            tvTerminalName.setText(item.getTerminalName());
            tvSubmitter.setText(item.getSubmitter());
            tvSubmitTime.setText(item.getSubmitTime());
            tvReceiptNo.setText(item.getReceiptNo());
            tvPaymentMethod.setText(item.getPaymentMethod());
            tvAmount.setText(item.getAmount());
            
            // 标签显示控制
            if (item.isHasTag()) {
                tvTag.setVisibility(View.VISIBLE);
                tvTag.setText(item.getTagText());
            } else {
                tvTag.setVisibility(View.GONE);
            }
        }
    }
}

